package com.yunkss.eftool.crypto.params;

import org.bouncycastle.crypto.params.ECDomainParameters;

/**
 * @author csx
 * @date 2022/2/18 8:49
 * @desc
 */

public class ParameterCalculator {
    public ParameterCalculator() {
    }

    public static int getCurveLength(ECDomainParameters domainParams) {
        return (domainParams.getCurve().getFieldSize() + 7) / 8;
    }

    public static byte[] fixBytes(int curveSize, byte[] src) {
        if (src.length == curveSize) {
            return src;
        } else {
            byte[] result = new byte[curveSize];
            if (src.length > curveSize) {
                System.arraycopy(src, src.length - result.length, result, 0, result.length);
            } else {
                System.arraycopy(src, 0, result, result.length - src.length, src.length);
            }

            return result;
        }
    }
}